//
// Created by wujehy on 2020/9/2.
//

#include "AppleLogSink.h"

__attribute__((visibility("default"))) __attribute__((used)) void call_apple_log(const char *tag, const char *body);

void AppleLogSink::send(google::LogSeverity severity, const char *full_filename, const char *base_filename, int line, const struct ::tm *tm_time, const char *message,
                        size_t message_len)
{
    std::string log_body_str = google::LogSink::ToString(
            severity,
            full_filename,
            line,
            tm_time,
            message,
            message_len);
    if (severity == 0)
    {
        call_apple_log("INFO", log_body_str.c_str());
//                NSLog(@"[INFO] :%s", log_body_str.c_str());
    } else if (severity == 1)
    {
        call_apple_log("WARN", log_body_str.c_str());
//                NSLog(@"[WARN] :%s", log_body_str.c_str());
    } else if (severity == 2)
    {
        call_apple_log("ERROR", log_body_str.c_str());
//                NSLog(@"[ERROR] :%s", log_body_str.c_str());
    } else if (severity == 3)
    {
        call_apple_log("FATAL", log_body_str.c_str());
//                NSLog(@"[FATAL] :%s", log_body_str.c_str());
    } else if (severity == 4)
    {
        call_apple_log("SILENT", log_body_str.c_str());
//                NSLog(@"[SILENT] :%s", log_body_str.c_str());
    }
}
//
//class AppleLogSink : public google::LogSink{
//        public:
//        void send(google::LogSeverity severity, const char* full_filename,
//        const char* base_filename, int line,
//        const struct::tm* tm_time,
//        const char* message, size_t message_len)  override  {
//            std::string log_body_str = google::LogSink::ToString(
//                    severity,
//                    full_filename,
//                    line,
//                    tm_time,
//                    message,
//                    message_len);
//            if (severity == 0)
//            {
//                NSLog(@"[INFO] :%s", log_body_str.c_str());
//            } else if (severity == 1)
//            {
//                NSLog(@"[WARN] :%s", log_body_str.c_str());
//            } else if (severity == 2)
//            {
//                NSLog(@"[ERROR] :%s", log_body_str.c_str());
//            } else if (severity == 3)
//            {
//                NSLog(@"[FATAL] :%s", log_body_str.c_str());
//            } else if (severity == 4)
//            {
//                NSLog(@"[SILENT] :%s", log_body_str.c_str());
//            }
//        }
//};
//
//void AppleLogSink::send(google::LogSeverity severity, const char* full_filename,
//                        const char* base_filename, int line,
//                        const struct::tm* tm_time,
//                        const char* message, size_t message_len)
//{
//    std::string log_body_str = google::LogSink::ToString(
//            severity,
//            full_filename,
//            line,
//            tm_time,
//            message,
//            message_len);
//    if (severity == 0)
//    {
//        NSLog(@"[INFO] :%s", log_body_str.c_str());
//    } else if (severity == 1)
//    {
//        NSLog(@"[WARN] :%s", log_body_str.c_str());
//    } else if (severity == 2)
//    {
//        NSLog(@"[ERROR] :%s", log_body_str.c_str());
//    } else if (severity == 3)
//    {
//        NSLog(@"[FATAL] :%s", log_body_str.c_str());
//    } else if (severity == 4)
//    {
//        NSLog(@"[SILENT] :%s", log_body_str.c_str());
//    }
//}
//}


